from file_reader_define import JSONFileReader, CSVFileReader
from pymysql import Connection

csv_file_reader = CSVFileReader('E:/PythonBasicKnowledge/11 python和数据库/综合案例/2011年1月销售数据.txt')
json_file_reader = JSONFileReader('E:/PythonBasicKnowledge/11 python和数据库/综合案例/2011年2月销售数据JSON.txt')
order_info1 = csv_file_reader.read()
order_info2 = json_file_reader.read()
total_order_info = order_info1 + order_info2

conn = Connection(
    host='localhost',
    port=3306,
    user='root',
    password='success',
    autocommit=True
)
conn.select_db('pysql')

cursor = conn.cursor()

for item in total_order_info:
    sql = F'insert into orders (order_date, order_id, money, province) ' \
          F'values ("{item.date}", "{item.order_id}", {item.money}, "{item.province}")'
    cursor.execute(sql)

conn.close()
